home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / THINKC / 4_0 / DIZZY / SRC / TOOL.C < prev    next >
Text File  |  1990-12-29  |  6KB  |  256 lines

  1. /*
  2. >>    Dizzy 1.0 Menu.c
  3. >>
  4. >>    A digital circuit simulator & design program for the X Window System
  5. >>
  6. >>    Copyright 1990 Juri Munkki, all rights reserved
  7. >>
  8. >>    Please read the included file called "DizzyDoc" for information on
  9. >>    what your rights are concerning this product.
  10. */
  11.  
  12. #include "dizzy.h"
  13.  
  14. /*
  15. >>    Mouse button functions are marked by what I call "tags" in the
  16. >>    tool palette. This routine draws those tags into the palette.
  17. */
  18. void    InvertButtonTag(index)
  19. int     index;
  20. {
  21.                 Rect            src,dest;
  22.     register    ToolSelection    *sel;
  23.  
  24.     if(index>=0 && index<MOUSE_BUTTONS)
  25.     {    sel= &ToolButtons[index];
  26.         if(sel->Function)
  27.         {    src.left=index*7;
  28.             src.right=src.left+7;
  29.             src.top=0;
  30.             src.bottom=6;
  31.             
  32.             dest=src;
  33.             OffsetRect(&dest,sel->Prime.left+1,sel->Prime.top+1);
  34.             if(sel->Function==1)
  35.             {    OffsetRect(&dest,index*24,0);
  36.             }
  37. #ifdef MACINTOSH
  38.             CopyBits(&ButtonBits,&MyWind->portBits,&src,&dest,srcXor,0L);
  39. #else
  40.             PenXor();
  41.             MiscPixCopy(src.left,src.top,&dest);
  42.             PenCopy();
  43. #endif
  44.             if(sel->Function < 0)
  45.             {    dest=src;
  46.                 OffsetRect(&dest,sel->Secondary.left+index*24+1,sel->Secondary.top+1);
  47. #ifdef MACINTOSH
  48.                 CopyBits(&ButtonBits,&MyWind->portBits,&src,&dest,srcXor,0L);
  49. #else
  50.                 PenXor();
  51.                 MiscPixCopy(src.left,src.top,&dest);
  52.                 PenCopy();
  53. #endif
  54.             }
  55.         }
  56.     }
  57. }
  58.  
  59. /*
  60. >>    This routine is called in response to an update/expose event.
  61. >>    It just redraws all the button tags.
  62. */
  63. void    UpdateButtonTags()
  64. {
  65.     int     i;
  66.     
  67.     for(i=0;i<MOUSE_BUTTONS;i++)
  68.     {    InvertButtonTag(i);
  69.     }
  70.     
  71.     PenXor();
  72.     FrameRect(&InputFrame);
  73.     PenCopy();
  74. }
  75.  
  76. /*
  77. >>    The way a double click is detected on the Macintosh is
  78. >>    very specific. In the unix version, it suffices to click
  79. >>    the same tool twice. You can go have a coke in between
  80. >>    the clicks, if you feel so and it will still work. These
  81. >>    variables and the following routine are for double click
  82. >>    detection.
  83. */
  84. static    long    DoubleTimer=0;
  85. static    int     DoubleButton= -1;
  86. static    int     DoubleFunction=0;
  87.  
  88. void    CancelDoubleToolClick()
  89. {
  90. /*    Button -1 should not exist. Thus, the next click is not a double click. */
  91.     DoubleButton= -1;
  92. }
  93.  
  94. /*
  95. >>    This routine is called in response to a mousedown in the
  96. >>    tool palette. It tracks the mouse and determines what was
  97. >>    selected. The selection is just marked and remembered. There
  98. >>    is no further action. Double clicks are detected.
  99. */
  100. void    DoToolClick()
  101. {
  102.     Rect        HiliteRect,OldHiliteRect,Inside,NotRect;
  103.     int         HiliteItem,NewHilite,NotIsOn,i,downflag;
  104.     Point        MousePoint;
  105.     int         WhichButton;
  106.     int         DEnable;
  107.     
  108.     WhichButton=GetDownButton();
  109.     
  110.     if(DoubleButton==WhichButton)
  111.         DEnable= -1;    /*    Same button twice. Possibly double click.    */
  112.     else
  113.         DEnable=0;
  114.  
  115. #ifdef    MACINTOSH        /*    Macintosh requires double click timing.     */
  116.     if(DoubleTimer+GetDblTime()<MyEvent.when)
  117.         DEnable=0;
  118.  
  119.     SetPort(MyWind);
  120. #endif
  121.  
  122.     DoubleButton=WhichButton;    /*    Remember for next time.             */
  123.  
  124.     Inside.left=ToolR.left+33;    /*    Define active tool palette bounds.    */
  125.     Inside.right=ToolR.right-3; /*    Eliminate shadow area.                */
  126.     Inside.top=ToolR.top+1;
  127.     Inside.bottom=ToolR.bottom-3;
  128.  
  129.     HiliteItem=0;                /*    Nothing selected.                    */
  130.     NotIsOn=0;                    /*    The "NOT" modifier is not on.        */
  131.     
  132.     do    /*    Track mouse until button comes up.                            */
  133.     {    downflag=GetMouseTrackEvent(&MousePoint);
  134.         if(PtInRect(MousePoint,&Inside))
  135.         {    MousePoint.v-=Inside.top;
  136.             NewHilite=MousePoint.v/24;    /*    24 pixel high buttons.        */
  137.  
  138.             HiliteRect=Inside;
  139.             HiliteRect.top=Inside.top+24*NewHilite;
  140.             HiliteRect.bottom=HiliteRect.top+23;
  141.  
  142.             if(NewHilite)        /*    Is this something else than "NOT"?    */
  143.             {    NewHilite=NewHilite*3-2;    /*    Three buttons/row.        */
  144.                 MousePoint.h-=Inside.left;
  145.                 MousePoint.h/=24;            /*    24 pixel wide buttons.    */
  146.                 NewHilite+=MousePoint.h;
  147.                 HiliteRect.left+=MousePoint.h*24;
  148.                 HiliteRect.right=HiliteRect.left+23;
  149.             }
  150.             
  151.             NewHilite++;            /*    Adjust so that 0 is unused.     */
  152.             
  153.             if(NotIsOn && NewHilite>4)    /*    Deselect "NOT" option.        */
  154.             {    NotIsOn=0;
  155.                 HILITEMODE;
  156.                 InvertRect(&NotRect);
  157.             }
  158.             
  159.             if(NotIsOn && NewHilite==1) /*    Deselect "NOT" option.        */
  160.             {    if(HiliteItem)    /*    Unhilite old item.                    */
  161.                 {    HILITEMODE;
  162.                     InvertRect(&OldHiliteRect);
  163.                 }
  164.                 NotIsOn=0;
  165.                 HiliteItem=1;    /*    This item is already hilited.        */
  166.             }        
  167.  
  168.             /*    Move from NOT to something that accepts "NOT"?            */
  169.             if(NewHilite<5 && NewHilite!=1 && HiliteItem==1)
  170.             {    NotIsOn= -1;
  171.                 NotRect=OldHiliteRect;
  172.                 HiliteItem=NewHilite;
  173.                 HILITEMODE;
  174.                 InvertRect(&HiliteRect);
  175.             }    
  176.         }
  177.         else    /*    Mouse is outside active area.                        */
  178.         {    NewHilite=0;
  179.             if(NotIsOn)
  180.             {    NotIsOn=0;
  181.                 HILITEMODE;
  182.                 InvertRect(&NotRect);
  183.             }
  184.         }
  185.         if(HiliteItem!=NewHilite)    /*    Do we have to change the hilite?    */
  186.         {    if(HiliteItem)            /*    Unhilite old item.                    */
  187.             {    HILITEMODE
  188.                 InvertRect(&OldHiliteRect);
  189.             }
  190.             if(NewHilite)            /*    Hilite new item.                    */
  191.             {    HILITEMODE
  192.                 InvertRect(&HiliteRect);
  193.             }
  194.         }
  195.         HiliteItem=NewHilite;
  196.         OldHiliteRect=HiliteRect;
  197.     }    while(downflag);            /*    Did mouse button come up?            */
  198.  
  199. #ifdef    MACINTOSH
  200.     DoubleTimer=MyEvent.when;
  201. #endif
  202.         
  203.     if(HiliteItem)                    /*    Was a tool selected?                */
  204.     {    for(i=MenuFlash*2;i;i--)    /*    Flash that tool.                    */
  205.         {    long    dummy;
  206.         
  207.             HILITEMODE
  208.             InvertRect(&OldHiliteRect);
  209.             if(NotIsOn)
  210.             {    HILITEMODE;
  211.                 InvertRect(&NotRect);
  212.             }
  213.             Delay(2,&dummy);
  214.         }    
  215.  
  216.         HILITEMODE                    /*    Unhilite tool.                        */
  217.         InvertRect(&OldHiliteRect);
  218.  
  219.         if(NotIsOn)                 /*    Unhilite NOT.                        */
  220.         {    HILITEMODE;
  221.             InvertRect(&NotRect);
  222.         }
  223.         
  224.         /*    Did user select the number of inputs in AND_, OR_,...            */
  225.         if(HiliteItem>=5 && HiliteItem <=7)
  226.         {    PenXor();
  227.             FrameRect(&InputFrame);
  228.             InputFrame=OldHiliteRect;
  229.             InsetRect(&InputFrame,1,1);
  230.             InputSelector=HiliteItem-3;
  231.             FrameRect(&InputFrame);
  232.             PenCopy();
  233.         }
  234.         else    /*    User selected a real tool. Store it in ToolButtons.     */
  235.         {    InvertButtonTag(WhichButton);    /*    Undraw old tag.             */
  236.         
  237.             if(NotIsOn)
  238.             {    HiliteItem= -HiliteItem;
  239.                 ToolButtons[WhichButton].Secondary=NotRect;
  240.             }
  241.             else
  242.             {    ToolButtons[WhichButton].Secondary=NilRect;
  243.             }
  244.             ToolButtons[WhichButton].Function=HiliteItem;
  245.             ToolButtons[WhichButton].Prime=OldHiliteRect;
  246.             
  247.             if(HiliteItem==DoubleFunction && DEnable)    /*    Double click?    */
  248.             {    ToolLocks[WhichButton]=ToolButtons[WhichButton];
  249.             }
  250.             DoubleFunction=HiliteItem;
  251.  
  252.             InvertButtonTag(WhichButton);    /*    Draw new tag.                */
  253.         }
  254.     }
  255. }
  256.